var ycw_vue = new Vue({
  el: "#main",
  data: {
    //is_mobile=false,
  },
  filters: {
    //过滤器
    formatMoney: function(value) {
      return "￥" + value.toFixed(2);
    }
  },
  mounted: function() {
    //入口方法
    this.$nextTick(function() {
      this.first();
    });
  },
  methods: {
    //方法
    first: function() {
      var _this = this;
      // _this.$http.post("https://www.youchangwang.cn/home/index/getdata", {'info': "1.0.1"}).then(function(res) {
      //     console.log(res);
      // });
      _this.$http
        .post("http://www.youchangwang.cn/home/index/getdata",{"info":"1.0.1"},{emulateJSON:true})
        .then(res => {
          //成功胡回调
          console.log(res);
        })
        .catch(res => {
          //失败的回掉
          console.log(res);
        });  
    },
    changeMoney: function(product, way) {
      if (way > 0) {
        product.productQuantity++;
      } else {
        product.productQuantity--;
        if (product.productQuantity < 1) {
          product.productQuantity = 1;
        }
      }
      this.calcTotalPrice();
    },
    selectedProduct: function(item) {
      if (typeof item.checked == "undefined") {
        Vue.set(item, "checked", true);
        //this.$set(item,"checked",true);
      } else {
        item.checked = !item.checked;
      }
      this.calcTotalPrice();
    },
    checkAll: function(flag) {
      this.checkAllFlag = flag;
      var _this = this;
      this.productList.forEach(function(item, index) {
        if (typeof item.checked == "undefined") {
          _this.$set(item, "checked", _this.checkAllFlag);
        } else {
          item.checked = _this.checkAllFlag;
        }
      });
      this.calcTotalPrice();
    },
    calcTotalPrice: function() {
      var _this = this;
      _this.totalMoney = 0;
      this.productList.forEach(function(item, index) {
        if (item.checked) {
          _this.totalMoney += item.productPrice * item.productQuantity;
        }
      });
    },
    delConfirm: function(item) {
      this.delFlag = true;
      this.curProduct = item;
    },
    delProduct: function() {
      var index = this.productList.indexOf(this.curProduct);
      this.productList.splice(index, 1);
      this.delFlag = false;
    }
  }
});
//setTimeout(() => {
//	_this.getListIng();
//}, 1000);
Vue.filter("money", function(value, type) {
  return "￥" + value.toFixed(2) + type;
});
